//
//  LzwBellViewController.m
//  NewHalfsugar
//
//  Created by 刘志武 on 15/12/31.
//  Copyright © 2015年 刘志武. All rights reserved.
//

#import "LzwBellViewController.h"
#import "LzwBellTableViewCell.h"
#import "Block.h"
#import "LzwBellDetailController.h"
#import "LzwSingleton.h"
#import "LzwbaseTableView.h"
@interface LzwBellViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, retain) LzwbaseTableView *myBelltableView;


@end

@implementation LzwBellViewController

-(void)dealloc{
    
    [_myBelltableView release];
    [super dealloc];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor greenColor];
    self.navigationItem.title = @"星推荐";
    
    [self.navigationController.navigationBar setTitleTextAttributes:
     
     
     @{NSFontAttributeName:[UIFont systemFontOfSize:20 * WIDTH],
       
       
       NSForegroundColorAttributeName:[UIColor whiteColor]}];
    
    
    self.myBelltableView = [[LzwbaseTableView alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
    self.myBelltableView.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:self.myBelltableView];
    
    self.myBelltableView.delegate = self;
    self.myBelltableView.dataSource = self;
    //注册cell
//    [self.myBelltableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
   [self.myBelltableView registerClass:[LzwBellTableViewCell class] forCellReuseIdentifier:@"cellBell"];

    self.arrayBell = [NSMutableArray array];
    self.arrayDeta = [NSMutableArray array];
    
    
//    NSMutableArray *array1 = [[LzwSingleton shareDataBase] selectBellTable];
//    self.arrayBell = [NSMutableArray arrayWithArray:array1];
    
    NSString *string = @"http://open3.bantangapp.com/users/notice/redSpot";
    
    NSDictionary *dicD = @{@"app_installtime":@"1451365479.933367", @"app_versions":@"5.1.1", @"channel_name":@"appStore", @"client_id":@"bt_app_ios", @"client_secret":@"9c1e6634ce1c5098e056628cd66a17a5", @"device_token":@"c02c60075e7bab110fbdf27e15de3cb61e97360c4ea3545fd8a5936e46c28ccb", @"oauth_token":@"a41d3848f43102aa7759c27ba2c0fe8f", @"os_versions":@"9.1", @"screensize":@"640", @"track_device_info":@"iPhone5%2C3", @"track_deviceid":@"A80585E3-D6AD-4A53-BE1C-5963901C96E5", @"track_user_id":@"1746436", @"type":@"1", @"v":@"9"};
    
    
    //@{@"client_id":@"bt_app_android", @"client_secret":@"ffcda7a1c4ff338e05c42e7972ba7b8d", @"track_user_id":@"1717728", @"oauth_token":@"d6018d97f512aaf96c1dcac6a5873a3a", @"track_deviceid":@"866661020046431", @"track_device_info":@"Bird+V90", @"channel_name":@"yingyonghui", @"app_installtime":@"1451027637075", @"app_versions":@"5.1.1", @"os_versions":@"4.4.2", @"screensize":@"480", @"v":@"9", @"type":@"1"};
    //=&=&=&=&=&=&=&=&=&=&=&=&=&=
    
    [Block creatingDataTask:string parameters:dicD Cookie:nil User_Agent:nil successAFNBlock:^(id resuposeObject) {
        
        NSMutableDictionary *dic = [resuposeObject objectForKey:@"data"];
        
        NSMutableArray *array = [dic objectForKey:@"element"];
        
        for (NSMutableDictionary *diction in array) {
            
            LzwBellModle *modleBel = [[LzwBellModle alloc]init];
            
            [modleBel setValuesForKeysWithDictionary:diction];
            
            [self.arrayBell addObject:modleBel];
            
            
        }
        
    
        
        [self.myBelltableView reloadData];
        
    }];
    
    
    
}

//设置分区
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}
//设置row
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
//    if (section == 0) {
//        return 4;
//    }
    return self.arrayBell.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
//    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    
    static NSString *Indentifire = @"cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Indentifire];
    
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:Indentifire];
    
    

    }
    if (indexPath.section == 0) {
        
    
        LzwBellTableViewCell *cellBell = [tableView dequeueReusableCellWithIdentifier:@"cellBell"];
        
        cellBell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        
        cellBell.modleBell = [self.arrayBell objectAtIndex:indexPath.row];
        
        return cellBell;

    }
    
    return cell;
}
//设置点击cell触发事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    
    LzwBellDetailController *detail = [[LzwBellDetailController alloc]init];
   
    detail.modleB = [self.arrayBell objectAtIndex:indexPath.row];
    [self.navigationController pushViewController:detail animated:YES];

    
}


//设置row的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
//    if (indexPath.section == 0) {
//        return 60;
//    }
    
    return 140;
    
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
